/******************************************************************************

    Copyright (C) 2006 Alessio Stalla (alessiostalla@gmail.com)

    This file is part of PrettyProlog.

    PrettyProlog is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    PrettyProlog is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with PrettyProlog; if not, write to the Free Software
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

    See the file COPYING for further details.

 *****************************************************************************/

package prettyprolog.engine.syspreds;

import java.util.List;

import prettyprolog.datatypes.Substitution;
import prettyprolog.datatypes.Term;
import prettyprolog.engine.Engine;

/**
 * Implements the write/1 system predicate. It prints its argument to the output
 * and succeeds.
 */
public class Write extends SystemPredicate {

	private static final Write inst = new Write();

	private Write() {
		super(1);
	}

	/** Returns the only instance of this system predicate. */
	public static Write getInstance() {
		return inst;
	}

	protected SyspredEffect doCall(Engine en, Substitution subst, List<Term> args)
			throws SyspredException {
		en.getIOManager().output(args.get(0).toString());
		return new SyspredEffect(false, subst);
	}

	public boolean isBacktrackable() {
		return false;
	}

	public String toString() {
		return super.toString() + " (write/1)";
	}
}